package com.ShottingWord.shared;

import java.util.ArrayList;

/**
 * 
 * The state of the game, 
 * Recording level, total time, round time, score,
 *  word, pictures, 
 * @author 
 *
 */

public class State {
	private int level;
	private int score;
	private int remaining_total_time;
	private int remaining_round_time;
	private int remaining_word_num;
	private GameResult game_result;
	private WordMap word_map;
	private ArrayList<String> word_list;
	private String[] pic_ids;
	private String active_word;
	private double accuracy;
	private int totalshot;
	
	public WordMap getWordMap()	{return word_map;}
	public int getTotalShot()	{return totalshot;}
	public ArrayList<String>	getWordList()	{return word_list;}
	public int getRemainingWordNum()	{return remaining_word_num;}
	public int getLevel()	{return level;}
	public int getRemainingTotal_time()	{return remaining_total_time;}
	public int getRemainingRound_time()	{return remaining_round_time;}
	public int getScore()	{return score;}
	public String getActiveWord()	{return active_word;}
	public double getAccuracy()	{return accuracy;}
	public String[] getPic_Ids()	{return pic_ids;}
	
	public void setWordMap(WordMap x)	{word_map=x;}
	public void setLevel(int x)	{level=x;}
	public void setRemainingTotal_time(int x)	{remaining_total_time=x;}
	public void setRemainingRound_time(int x)	{remaining_round_time=x;}
	public void setScore(int x)	{score=x;}
	public void setRemainingWord_Num(int x)	{remaining_word_num=x;}
	public void setActiveWord(String s)	{active_word=s;}		
	public void setAccuracy(double x)	{accuracy=x;}
	public void setPic_Ids(String[] s)	{pic_ids=s;}
	public void setWordList(ArrayList<String> s)	{word_list=s;}	
	public void setTotalShot(int x)	{totalshot=x;}
	
	public GameResult callResult()	{
		accuracy=accuracy/totalshot;
		game_result=new GameResult(score,accuracy);
		return game_result;
		
	}
	
	/**
	 * this function should be for accessing freebase API and put all of them in wordmap
	 */
	public void populateWordMap()	{
		//still need to wait for the freebase data
	}
	
	public State(int level){
		word_map = new WordMap();
		initiate(level);
		populateWordMap();
	}	
	
	/**
	 * 
	 * Initiate the state.
	 * @param level
	 */
	public void initiate(int level){
		this.level = level;
		remaining_total_time = Global.TOTAL_TIME;//ms
		remaining_round_time = Global.ROUND_TIME;//ms
		remaining_word_num=level*Global.WORD_MULTIPLIER;
		score = 0;
		accuracy=0;
		totalshot=0;
		pic_ids=new String[level*Global.CHOICE_MULTIPLIER];
		game_result = null;
		active_word="";
		
	}
	/**
	 * for checking whether a word and pic match, returns boolean
	 * @param word
	 * @param pic
	 * @return
	 */
	public boolean checkPic(String word,String pic)	{
		boolean result=(word_map.getPicId(word).equals(pic)?true:false);
		return result;
	}
	
	
}
